import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TOpenRechargeGiftBag } from "../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { Cache } from "../cache/Cache";
type int = number;
//class OpenRechargeGiftBagConfig
    
    export  class OpenRechargeGiftBagConfig
    {
        constructor()
        {
            
            this._rechargeMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._rechargeTargetArr = [];
            this._consumeArr = [];
            this._consumeTwoArr = [];
            this._consumeThreeArr = [];
            this._mergeRechargeArr = [];
            this._consumeDayOneArr = [];
            this._consumeDayTwoArr = [];
            this._openRechargeArr = [];
            this._newYearCountArr = [];
            if (OpenRechargeGiftBagConfig._instance != null) 
            {
                throw new Error("OpenRechargeGiftBag 单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_open_recharge_gift_bag.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TOpenRechargeGiftBag();
                loc1.code = loc2.code;
                loc1.itemCode = loc2.itemCode;
                loc1.target = loc2.target;
                loc1.value = loc2.value;
                loc1.activetype = loc2.activetype;
                loc1.levelMax = loc2.levelMax;
                loc1.levelMin = loc2.levelMin;
                if (loc1.code <= 7) 
                {
                    this._rechargeMap[loc1.code] = loc1;
                    this._rechargeTargetArr.push(loc1.target);
                    continue;
                }
                if (loc1.activetype == 1) 
                {
                    this._consumeArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 2) 
                {
                    this._consumeTwoArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 3) 
                {
                    this._mergeRechargeArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 4) 
                {
                    this._consumeThreeArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 5) 
                {
                    this._consumeDayOneArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 6) 
                {
                    this._consumeDayTwoArr.push(loc1);
                    continue;
                }
                if (loc1.activetype == 9) 
                {
                    this._openRechargeArr.push(loc1);
                    continue;
                }
                if (loc1.activetype != 10) 
                {
                    continue;
                }
                this._newYearCountArr.push(loc1);
            }
            this._rechargeTargetArr.sort(Array.NUMERIC);
            return;
        }

        public getOpenRechargeGiftBagMap(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._rechargeMap;
        }

        public getRechargeTargetArr(): Array<any>
        {
            return this._rechargeTargetArr;
        }

        public getConsumeCountGiftBag(arg1: int, arg2: int): Array<any>
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            if (arg1 == EActiveType._EActiveTypeDayRechargeGiftBag) 
            {
                return this._newYearCountArr;
            }
            this._curConsumeGiftBagArr = [];
            loc2 = [];
            if (arg1 != EActiveType._EActiveTypeMergeRechargeGiftBag) 
            {
                if (arg1 != EActiveType._EActiveTypeConsumeCount) 
                {
                    if (arg1 != EActiveType._EActiveTypeConsumeCountTwo) 
                    {
                        if (arg1 != EActiveType._EActiveTypeConsumeCountThree) 
                        {
                            if (arg1 != EActiveType._EActiveTypeConsumeDay1) 
                            {
                                if (arg1 != EActiveType._EActiveTypeConsumeDay2) 
                                {
                                    if (arg1 == EActiveType._EActiveTypeRechargeGiftBagEx) 
                                    {
                                        loc2 = this._openRechargeArr;
                                    }
                                }
                                else 
                                {
                                    loc2 = this._consumeDayTwoArr;
                                }
                            }
                            else 
                            {
                                loc2 = this._consumeDayOneArr;
                            }
                        }
                        else 
                        {
                            loc2 = this._consumeThreeArr;
                        }
                    }
                    else 
                    {
                        loc2 = this._consumeTwoArr;
                    }
                }
                else 
                {
                    loc2 = this._consumeArr;
                }
            }
            else 
            {
                loc2 = this._mergeRechargeArr;
                arg2 = Cache.instance.role.curWorldLevel;
            }
            loc3 = 0;
            while (loc3 < loc2.length) 
            {
                loc1 = loc2[loc3] as TOpenRechargeGiftBag;
                if (loc1 && arg2 >= loc1.levelMin && arg2 <= loc1.levelMax) 
                {
                    this._curConsumeGiftBagArr.push(loc1);
                }
                ++loc3;
            }
            return this._curConsumeGiftBagArr;
        }

        public getConsumeCountTargetArr(arg1: int, arg2: int): Array<any>
        {
            var loc2=null;
            this._curConsumeTagArr = [];
            var loc1=[];
            if (arg1 != EActiveType._EActiveTypeMergeRechargeGiftBag) 
            {
                if (arg1 != EActiveType._EActiveTypeConsumeCount) 
                {
                    if (arg1 != EActiveType._EActiveTypeConsumeCountTwo) 
                    {
                        if (arg1 != EActiveType._EActiveTypeConsumeCountThree) 
                        {
                            if (arg1 != EActiveType._EActiveTypeConsumeDay1) 
                            {
                                if (arg1 != EActiveType._EActiveTypeConsumeDay2) 
                                {
                                    if (arg1 != EActiveType._EActiveTypeRechargeGiftBagEx) 
                                    {
                                        if (arg1 == EActiveType._EActiveTypeDayRechargeGiftBag) 
                                        {
                                            loc1 = this._newYearCountArr;
                                        }
                                    }
                                    else 
                                    {
                                        loc1 = this._openRechargeArr;
                                    }
                                }
                                else 
                                {
                                    loc1 = this._consumeDayTwoArr;
                                }
                            }
                            else 
                            {
                                loc1 = this._consumeDayOneArr;
                            }
                        }
                        else 
                        {
                            loc1 = this._consumeThreeArr;
                        }
                    }
                    else 
                    {
                        loc1 = this._consumeTwoArr;
                    }
                }
                else 
                {
                    loc1 = this._consumeArr;
                }
            }
            else 
            {
                loc1 = this._mergeRechargeArr;
                arg2 = Cache.instance.role.curWorldLevel;
            }
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc2 = loc1[loc3] as TOpenRechargeGiftBag;
                if (arg1 == EActiveType._EActiveTypeDayRechargeGiftBag) 
                {
                    this._curConsumeTagArr.push(loc2.target);
                }
                else if (loc2 && arg2 >= loc2.levelMin && arg2 <= loc2.levelMax) 
                {
                    this._curConsumeTagArr.push(loc2.target);
                }
                ++loc3;
            }
            this._curConsumeTagArr.sort(Array.NUMERIC);
            return this._curConsumeTagArr;
        }

        public getGiftBagIndex(arg1: TOpenRechargeGiftBag): int
        {
            var loc3=0;
            var loc5=null;
            var loc6=0;
            var loc1=[];
            var loc2=false;
            if (arg1.activetype == 3) 
            {
                if (arg1.activetype == 3) 
                {
                    loc1 = this._mergeRechargeArr;
                    loc2 = true;
                    loc3 = Math.ceil(this._mergeRechargeArr.length / 2);
                }
            }
            else 
            {
                loc1 = this._curConsumeGiftBagArr;
            }
            var loc4=1;
            if (loc1) 
            {
                loc6 = 0;
                while (loc6 < loc1.length) 
                {
                    if ((loc5 = loc1[loc6] as TOpenRechargeGiftBag) == arg1) 
                    {
                        if (loc2) 
                        {
                            loc4 = loc6 % loc3 + 1;
                        }
                        else 
                        {
                            loc4 = loc6 + 1;
                        }
                    }
                    ++loc6;
                }
            }
            return loc4;
        }

        public getGiftBagInfoByTarget(arg1: int, arg2: int, arg3: int): TOpenRechargeGiftBag
        {
            var loc1=null;
            var loc2=null;
            if (arg2 != 1) 
            {
                loc2 = [];
                if (arg2 != EActiveType._EActiveTypeMergeRechargeGiftBag) 
                {
                    if (arg2 != EActiveType._EActiveTypeConsumeCount) 
                    {
                        if (arg2 != EActiveType._EActiveTypeConsumeCountTwo) 
                        {
                            if (arg2 != EActiveType._EActiveTypeConsumeCountThree) 
                            {
                                if (arg2 != EActiveType._EActiveTypeConsumeDay1) 
                                {
                                    if (arg2 != EActiveType._EActiveTypeConsumeDay2) 
                                    {
                                        if (arg2 != EActiveType._EActiveTypeRechargeGiftBagEx) 
                                        {
                                            if (arg2 == EActiveType._EActiveTypeDayRechargeGiftBag) 
                                            {
                                                loc2 = this._newYearCountArr;
                                            }
                                        }
                                        else 
                                        {
                                            loc2 = this._openRechargeArr;
                                        }
                                    }
                                    else 
                                    {
                                        loc2 = this._consumeDayTwoArr;
                                    }
                                }
                                else 
                                {
                                    loc2 = this._consumeDayOneArr;
                                }
                            }
                            else 
                            {
                                loc2 = this._consumeThreeArr;
                            }
                        }
                        else 
                        {
                            loc2 = this._consumeTwoArr;
                        }
                    }
                    else 
                    {
                        loc2 = this._consumeArr;
                    }
                }
                else 
                {
                    loc2 = this._mergeRechargeArr;
                    arg3 = Cache.instance.role.curWorldLevel;
                }
                loc3 = 0;
                loc4 = loc2;
                for(loc1 of loc4) 
                {
                    if (!(arg1 == loc1.target && arg3 >= loc1.levelMin && arg3 <= loc1.levelMax)) 
                    {
                        continue;
                    }
                    break;
                }
            }
            else 
            {
                var loc3=0;
                var loc4=this._rechargeMap;
                for(loc1 of loc4) 
                {
                    if (arg1 != loc1.target) 
                    {
                        continue;
                    }
                    break;
                }
            }
            return loc1;
        }

        public getFinalInfoByCode(arg1: int, arg2: int): TOpenRechargeGiftBag
        {
            var loc1=null;
            var loc2=null;
            if (arg2 != 1) 
            {
                loc2 = [];
                if (arg2 != EActiveType._EActiveTypeConsumeCount) 
                {
                    if (arg2 != EActiveType._EActiveTypeConsumeCountTwo) 
                    {
                        if (arg2 != EActiveType._EActiveTypeConsumeCountThree) 
                        {
                            if (arg2 != EActiveType._EActiveTypeConsumeDay1) 
                            {
                                if (arg2 != EActiveType._EActiveTypeConsumeDay2) 
                                {
                                    if (arg2 == EActiveType._EActiveTypeRechargeGiftBagEx) 
                                    {
                                        loc2 = this._openRechargeArr;
                                    }
                                }
                                else 
                                {
                                    loc2 = this._consumeDayTwoArr;
                                }
                            }
                            else 
                            {
                                loc2 = this._consumeDayOneArr;
                            }
                        }
                        else 
                        {
                            loc2 = this._consumeThreeArr;
                        }
                    }
                    else 
                    {
                        loc2 = this._consumeTwoArr;
                    }
                }
                else 
                {
                    loc2 = this._consumeArr;
                }
                var loc3=0;
                var loc4=loc2;
                for(loc1 of loc4) 
                {
                    if (arg1 != loc1.code) 
                    {
                        continue;
                    }
                    break;
                }
            }
            else 
            {
                loc1 = this._rechargeMap[arg1];
            }
            return loc1;
        }

        public static get instance(): OpenRechargeGiftBagConfig
        {
            if (OpenRechargeGiftBagConfig._instance == null) 
            {
                OpenRechargeGiftBagConfig._instance = new OpenRechargeGiftBagConfig();
            }
            return OpenRechargeGiftBagConfig._instance;
        }

        /* internal */ /* var */_rechargeMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_rechargeTargetArr: Array<any>;

        /* internal */ /* var */_consumeArr: Array<any>;

        /* internal */ /* var */_consumeTwoArr: Array<any>;

        /* internal */ /* var */_consumeThreeArr: Array<any>;

        /* internal */ /* var */_mergeRechargeArr: Array<any>;

        /* internal */ /* var */_consumeDayOneArr: Array<any>;

        /* internal */ /* var */_consumeDayTwoArr: Array<any>;

        /* internal */ /* var */_openRechargeArr: Array<any>;

        /* internal */ /* var */_newYearCountArr: Array<any>;

        /* internal */ /* var */_curConsumeGiftBagArr: Array<any>;

        /* internal */ /* var */_curConsumeTagArr: Array<any>;

        /* internal */ static /* var */_instance: OpenRechargeGiftBagConfig;
    }
